473,465 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Javascript intrepreting an apostrophe as a delimiter while displaying a perl variable

I am working on a cgi script that is suppose to pop-up a javascript
box from the following perl variables:$TodayDate, $LinkCity,
$LinkState. I recently encountered a problem with the $LinkCity
variable when the city Coeur d'Alene was read. It appears that
javascript is intrepreting the quote to end after d'. I've tried
reversing the quotes (instead of " ' ' ", ' " " ') and using the
javascript escape command. Neither worked. Please help!

example:
if ($AQI1 eq "Good") {
$message = &altQualityMessages($Pollutant{$TodayDay . $City .
$State},"Good");
$AQI1="<A HREF=\"javascript:PopUp(\'$TodayDate\',\'$LinkCity \',\'$LinkState\')\"
onMouseOver=\"window.status='$Pollutant{$TodayDay . $City . $State}
Forecast For $City, $State';return true\"

http://www.epa.gov/cgi-bin/airnow.cg...splay=FORECAST

javascript error:
missing ; before statement.
window.status='OZONE Forecast For Coeur d'Alene, ID';return true
Jul 20 '05 #1
3 12850
I had a similar problem with a PHP mailing tool I wrote where apostrophes in
a text interfered with the apostrophes in the form elements (value="$text").
I made a workaround with urlencoding and urldecoding the string.

One problem with this is that if you urlencode with Perl it is not sure that
the decodeURI function in javascript decodes it properly, you have to test
that (I am not familiar with Pearl, it does not work with PHP). I would try
adding a script in the HTML head, the output should look something like:

var jsLinkCity = encodeURI($LinkCity)

and then pass the variable jsLinkCity with the Popup function and decode it
again in the head of the popup window file.

You can also encode and decode it with Perl, but probably not encode it with
one and decode it with the other.

hth
Markus
"Jeanne" <br***********@epa.gov> schrieb im Newsbeitrag
news:61*************************@posting.google.co m...
I am working on a cgi script that is suppose to pop-up a javascript
box from the following perl variables:$TodayDate, $LinkCity,
$LinkState. I recently encountered a problem with the $LinkCity
variable when the city Coeur d'Alene was read. It appears that
javascript is intrepreting the quote to end after d'. I've tried
reversing the quotes (instead of " ' ' ", ' " " ') and using the
javascript escape command. Neither worked. Please help!

example:
if ($AQI1 eq "Good") {
$message = &altQualityMessages($Pollutant{$TodayDay . $City .
$State},"Good");
$AQI1="<A HREF=\"javascript:PopUp(\'$TodayDate\',\'$LinkCity \',\'$LinkState\')\" onMouseOver=\"window.status='$Pollutant{$TodayDay . $City . $State}
Forecast For $City, $State';return true\"

http://www.epa.gov/cgi-bin/airnow.cg...splay=FORECAST

javascript error:
missing ; before statement.
window.status='OZONE Forecast For Coeur d'Alene, ID';return true


Jul 20 '05 #2
> var jsLinkCity = encodeURI($LinkCity)

and then pass the variable jsLinkCity with the Popup function and decode it again in the head of the popup window file.

You can also encode and decode it with Perl, but probably not encode it with one and decode it with the other.


Actually, I don't think it would be a good idea to URL encode it, since the
only characters that'd stress out Javascript in a variable value would be
apostrophe and in certain cases backslash (like if for some reason a value
contained (and was supposed to contain) \' or \\ or \n). If you just use cgi
to replace every instance of \ with \\ and ' with \' your Javascript
variables will be correct (at least AFAIK ;)

Daniel
Jul 20 '05 #3
> I am working on a cgi script that is suppose to pop-up a javascript
box from the following perl variables:$TodayDate, $LinkCity,
$LinkState. I recently encountered a problem with the $LinkCity
variable when the city Coeur d'Alene was read. It appears that
javascript is intrepreting the quote to end after d'. I've tried
reversing the quotes (instead of " ' ' ", ' " " ') and using the
javascript escape command. Neither worked. Please help!

example:
if ($AQI1 eq "Good") {
$message = &altQualityMessages($Pollutant{$TodayDay . $City .
$State},"Good");
$AQI1="<A HREF=\"javascript:PopUp(\'$TodayDate\',\'$LinkCity \',\'$LinkState\')\" onMouseOver=\"window.status='$Pollutant{$TodayDay . $City . $State}
Forecast For $City, $State';return true\"


It bites that JavaScript does not have nesting string delimiters. Rebol does
(www.rebol.com), and I think that is quite civilized.

You need a slashify function which will insert a backslash before every quote,
single quote, and backslash in a string. Using such a function, your code will
get a lot easier to read, too.

http://www.crockford.com/javascript/remedial.html

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: john brown | last post by:
I'm new to perl programming and would like some help if at all possible. I'm trying to make a simple script where I can input a filename. To be exact something like "/home/song1.mp3". I want to...
2
by: Michael Sterling | last post by:
i'm using delphi 7 and have a query in which i'm trying to find names that have an apostrophe in them, i.e. "o'mally". my problem is that when i write my select statement i can't get the quotes...
22
by: Weston C | last post by:
I know of course that you can use <script src=""></script> in an HTML document to include javascript code you don't want to spill all over the page. I'm wondering if there's a way to include...
13
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
1
by: spacehopper_man | last post by:
hi - I am having "apostrophe in sql" problems ;) I am executing a stored procedure on SQL Server - and passing in a string parameter. the string has a single apostrophe in it. the call...
1
by: Rose | last post by:
Hi all, I'm trying to create a clickable link, but the pesky apostrophe is preventing the link from getting displayed properly. I'm displaying the contents of a folder (with contains the...
1
by: Tufty | last post by:
Hi, I have a webpage that lets the user upload an image. This is the posted to a perl script as a form var. The data is stored in SQL 2005 (as the new image object). I now need to get it back...
2
by: pleaseexplaintome | last post by:
Hi I have the following perl/cgi script snippet. The goal of this script is to pass a javascript variable to perl where it can be re-used later. Any help is appreciated, Thanks ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.